var t = getApp();

Page({
    data: {
        loveData: {
            love: 0,
            ratio: 0,
            least: 0,
            value: 0
        },
        love_nums: "",
        integral: "消费积分",
        loveName: "爱心值"
    },
    onLoad: function(t) {},
    onReady: function() {},
    onShow: function() {
        this.getyz_basic_info(), this.getdata();
    },
    loading: function(t) {
        wx.showToast({
            title: t,
            icon: "loading"
        });
    },
    getyz_basic_info: function() {
        try {
            var t = wx.getStorageSync("yz_basic_info");
            if (t) {
                var a = t.integral;
                this.setData({
                    integral: a,
                    loveName: t.love
                }), wx.setNavigationBarTitle({
                    title: a
                });
            }
        } catch (t) {}
    },
    getdata: function() {
        var a = this;
        this.loading("获取数据中...");
        var e = t.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.change-integral.index");
        t._postNetWork({
            url: e,
            success: function(t) {
                var e = t.data, o = e.result, n = e.msg, s = e.data;
                wx.hideToast(), 1 == o ? a.setData({
                    loveData: s
                }) : a.this.$toast(n);
            }
        });
    },
    $toast: function(t) {
        wx.showToast({
            title: t,
            icon: "none"
        });
    },
    setdata: function() {
        var a = this, e = this.data, o = e.love_nums, n = e.loveData;
        if (o <= 0 || "" === o) return this.$toast("转化的数量不能为0，也不能为空"), !1;
        if (1 * o > 1 * n.love) return this.$toast("转化的数量不能大于总数量"), !1;
        if (1 * o > 1 * (n.love - n.least)) return this.$toast("最低保留" + n.least + "爱心值"), 
        !1;
        this.loading("正在转化中...");
        var s = t.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.change-integral.change");
        t._postNetWork({
            url: s,
            data: {
                love_nums: o
            },
            success: function(t) {
                var e = t.data, o = e.result, n = e.msg, s = e.data;
                wx.hideToast(), 1 == o ? (wx.showToast(s), setTimeout(function() {
                    a.getdata();
                }, 1e3)) : a.$toast(n);
            }
        });
    },
    _bindinput: function(t) {
        var a = t.detail.value;
        this.setData({
            love_nums: a
        });
    },
    allLove: function() {
        var t = this.data.loveData, a = t.love, e = t.least;
        if (a <= e) return this.$toast("当前没有可转换的" + this.data.loveName), !1;
        this.setData({
            love_nums: a - e
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});